typecho常用代码记录
最近改typecho特别痛苦,我虽然学过php,那也是十几年前了,现在脑袋空空,看不懂了,只好把要用的记录下来,以备不时之需
Typecho调用分类目录的位置添加以下代码
<?php $this->widget('Widget_Archive@index', 'pageSize=6&type=category', 'slug=缩略码')
->parse('<li><a href="{permalink}">{title}</a></li>'); ?>
调用自定义字段
<?php $this->fields->fieldName ?>
<img class="tubiao"src="<?php Helper::options()->themeUrl('img/linju.svg'); ?>" alt="邻居">
读者墙
<?php
$period = time() - 999592000; // 999592000秒
$counts = Typecho_Db::get()->fetchAll(Typecho_Db::get()
->select('COUNT(author) AS cnt','author', 'url', 'mail')
->from('table.comments')
->where('created > ?', $period )
->where('status = ?', 'approved')
->where('type = ?', 'comment')
->where('authorId = ?', '0')
->group('author')
->order('cnt', Typecho_Db::SORT_DESC)
->limit(25)
);
$mostactive = '';
$avatar_path = 'http://www.gravatar.com/avatar/';
foreach ($counts as $count) {
$avatar = $avatar_path . md5(strtolower($count['mail'])) . '.jpg';
$c_url = $count['url']; if ( !$c_url ) $c_url = Helper::options()->siteUrl;
$mostactive .= "<a href='" . $c_url . "' title='" . $count['author'] . " (参与" . $count['cnt'] . "次互动)' target='_blank'><img src='" . $avatar . "' alt='" . $count['author'] . "的头像' class='avatar' width='32' height='32' /></a>\n";
}
echo $mostactive; ?>